const util = require('../../utils/util.js');
const api = require('../../config/api.js');
Page({
  data: {
    newGoods: [], // 新品首发
    hotGoods: [], // 人气推荐
    topics: [], // 专题精选
    brands: [], // 品牌制造商
    groupons: [], // 团购专区
    floorGoods: [], // 从居家开始的层级数据（二维数组）
    banner: [], // 轮播图数据
    channel: [], // 九宫格数据
    coupon: [], // 优惠卷
    goodsCount: 0 // 商品搜索, 共xx款好物(搜索框)
  },
  // 调用接口获取相关的数据
  getIndexData: function () {
    let that = this;
    util.request(api.IndexUrl).then(function (res) {
      if (res.errno === 0) {
        that.setData({
          newGoods: res.data.newGoodsList,
          hotGoods: res.data.hotGoodsList,
          topics: res.data.topicList,
          brands: res.data.brandList,
          floorGoods: res.data.floorGoodsList,
          banner: res.data.banner,
          groupons: res.data.grouponList,
          channel: res.data.channel,
          coupon: res.data.couponList
        });
      }
    });
    util.request(api.GoodsCount).then(function (res) {
      that.setData({
        goodsCount: res.data.goodsCount
      });
    });
  },
  onLoad: function (options) {
    this.getIndexData();
  }
})